<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb20">
<!--      <el-col :span="1.5">-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="房间" prop="premisesAddress">
        <el-input v-model="queryParams.premisesAddress" placeholder="请输入" clearable style="width: 240px"
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="上传时间">
        <el-date-picker v-model="dateRange" type="daterange" range-separator="~" start-placeholder="开始日期"
                        end-placeholder="结束日期" style="width: 240px"
                        value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item label="状态" prop="facilitiesState">
        <el-select v-model="queryParams.facilitiesState" placeholder="请选择" clearable style="width: 240px">
          <el-option v-for="item in dict.type.facilities_state" :key="item.value" :label="item.label"
                     :value="item.value"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane :label="item.label" :name="item.value" v-for="(item, index) in tabsList" :key="index"></el-tab-pane>
    </el-tabs>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelect">
      <el-table-column width="55" label="序号" align="center" key="lockName" prop="lockName"
                       :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="房间" align="center" prop="premisesAddress" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.premisesAddress }}</span>
        </template>
      </el-table-column>
      <el-table-column label="来源" align="center" prop="housePictureType" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ housePictureTypeMap[scope.row.housePictureType] }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最后上传时间" align="center" prop="applyDate" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ scope.row.createTime|formatDate('YYYY-MM-DD HH:mm') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="type" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.facilities_state"
            :value="scope.row.facilitiesState"
            v-if="scope.row.facilitiesState"
          />
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="图片数量" align="center" prop="pictureNumber" :show-overflow-tooltip="true">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleDetail(scope.row)">查看详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />
    <!--  详情弹出层   -->
    <Detail v-model="detailVisible" :title="title" :data="form" @success="getList"/>
  </div>
</template>

<script>
import Detail from './components/detail.vue'
import { getHousePictureList } from '@/api/houseManagement/housePicture'

export default {
  name: 'Index',
  dicts: ['facilities_state'],
  components: {
    Detail
  },
  data() {
    return {
      // 选中项
      activeName: '',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: null,
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 详情弹出层是否显示
      detailVisible: false,
      // 日期范围
      dateRange: [],
      // 表单参数
      form: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        premisesAddress: '',//房间名称
        housePictureType: '',//房屋相册类型：1.验房；2.清洁打扫；3.保洁；4.报修；5.看房；6.日常检查
        facilitiesState: '', //设施状态：1.正常；2.已损坏
      },
      // tabs列表
      tabsList: [
        {
          label: '全部',
          value: ''
        },
        {
          label: '验房',
          value: '1'
        },
        {
          label: '清洁打扫',
          value: '2'
        },
        {
          label: '保洁',
          value: '3'
        },
        {
          label: '报修',
          value: '4'
        },
        {
          label: '看房',
          value: '5'
        },
        {
          label: '日常检查',
          value: '6'
        }
      ],
      // 相册类型映射
      housePictureTypeMap: {
        '1': '验房',
        '2': '清洁打扫',
        '3': '保洁',
        '4': '报修',
        '5': '看房',
        '6': '日常检查'
      }
    }
  },
  computed: {
  },
  watch: {},
  created() {
    this.initData()

  },
  methods: {
    /** 初始化数据 */
    initData() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        premisesAddress: '',//房间名称
        housePictureType: '',//房屋相册类型：1.验房；2.清洁打扫；3.保洁；4.报修；5.看房；6.日常检查
        facilitiesState: '', //设施状态：1.正常；2.已损坏
      }
      this.handleQuery()
    },
    // 选项改变
    handleClick(tab, event) {
      console.log('tab', tab)
      this.activeName = tab.name
      this.queryParams.housePictureType = tab.name

      this.handleQuery()
    },
    // 选中项
    handleSelect(selection) {
      console.log('selection', selection)
      this.ids = selection.map(item => item.workOrderId)
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true
      getHousePictureList(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    handleDetail(row) {
      console.log('row', row)
      this.form = { ...row }
      this.detailVisible = true
      this.title = '工单详情'
    }
  }
}
</script>

<style lang="scss" scoped></style>
